package com.itruth.module.main;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.itruth.main.R;

public class MainGridViewAdapter extends BaseAdapter {
	
	private LayoutInflater inflater;
	
	private boolean isLeft;
	
	private String[] data;
	
	private int[] images;
	
	public MainGridViewAdapter(Context context, boolean isLeft) {
		inflater = LayoutInflater.from(context);
		this.isLeft = isLeft;
		init();
	}
	
	private void init() {
		
		data = new String[] { isLeft ? "执笔" : "查看", isLeft ? "分享" : "设置" };
		images = new int[] { isLeft ? R.drawable.moshi1 : R.drawable.moshi3,
				isLeft ? R.drawable.moshi2 : R.drawable.moshi4 };
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		convertView = inflater.inflate(R.layout.main_gv_item, null);
		ImageView iv = (ImageView)convertView.findViewById(R.id.item_imageview);
		TextView tv = (TextView)convertView.findViewById(R.id.item_textview);
		
		iv.setImageResource(images[position]);
		tv.setText(data[position]);
		return convertView;
	}
	
	@Override
	public int getCount() {
		return data.length;
	}
	
	
	@Override
	public Object getItem(int position) {
		return data[position];
	}
	
	@Override
	public long getItemId(int position) {
		return position;
	}
}
